


use "$clean/clean_all.dta", clear




keep if treatment==0

la var prior_comp "Belief: competition intentions"
la var posterior_comp "Belief: competition actual"

loc covars "female age member years_member experience canv_workshop prior_comp posterior_comp canvassing_yes days"

/* Balance tables */


    preserve

    clear all
    eststo clear
    estimates drop _all

    set obs 10
    qui gen x = 1
    qui gen y = 1

    forval i = 1/3 {

        qui eststo col`i': reg x y

    }

    restore

/* Statistics */

    loc tabletitle "Randomization check for experiment `expid'"
    loc rowstats ""
    loc rowlabels ""
    loc colnames " "App" "No App" "P-value(App = No App)""

    loc varlength: list sizeof covars
    loc varindex = 1

    mat def P1 = J(`varlength', 1, .)
    mat def P2 = J(`varlength', 1, .)
    mat def P3 = J(`varlength', 1, .)

    foreach var in `covars' {


        cap noi {
            qui sum `var' if app_download == 1  
            estadd loc `var'_m = string(r(mean), "%9.2f"): col1
        }

        cap noi {
            qui sum `var' if app_download == 0 
            estadd loc `var'_m = string(r(mean), "%9.2f"): col2
        }



        cap noi {
            qui reg `var' app_download, vce(r)
            qui test app_download = 0
            estadd loc `var'_m = string(r(p), "%9.3f"): col3
            mat def P3[`varindex', 1] = r(p)
        }
		

*				 cap noi {
 *           qui sum `var' 
 *           estadd loc `var'_m =  string(r(N), "%9.0f"): col4
 *       }

        loc rowstats "`rowstats' `var'_m `var'_sd"
        loc rowlabels "`rowlabels' `"`: var la `var''"' " " "

        loc ++varindex

    }
 
 
 
    esttab * using "$tables/Table_A4.tex", replace cells(none) booktabs nonotes nonum compress alignment(c) nogap noobs nobaselevels label mtitle(`colnames') stats(`rowstats', labels(`rowlabels'))
    eststo clear




